package com.maysahar;

import java.util.ArrayList;
import java.util.Collection;

import android.content.Context;

import com.maysahar.model.Entry;


public class EntryManager {

	private static EntryManager instance;
	private ArrayList<Entry> entries = null;
		
	private EntryManager() {
		
	}
	
	public static EntryManager getInstance() {
		if(instance == null) {
			instance = new EntryManager();
		}
		return instance;
	}
	
	public ArrayList<Entry> getEntries(Context ctx) throws Exception {
		EntryDAO dao = new EntryDAO(ctx);
		dao.open();
		ArrayList<Entry>entries = dao.select(DatabaseHelper.COLUMN_SETTING + " = 0");
		dao.close();
		return entries;
	}
	
	public ArrayList<Entry> getMatches(String filter, Context ctx) throws Exception {
		if(entries == null) {
			getEntries(ctx);
		}
		ArrayList<Entry> result = new ArrayList<Entry>();
		for(Entry entry : entries) {
			if(entry.getName().toLowerCase().contains(filter.toLowerCase())) {
				result.add(entry);
			}
		}
		return result;
	}
}
